<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="油管内容积(m³)" prop="tubingVolume">
				<u-input :border="border" placeholder="请输入油管内容积" v-model="model.tubingVolume" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="填砂量(m³)" prop="sandVolume">
				<u-input :border="border" placeholder="请输入填砂量" v-model="model.sandVolume" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="填砂管柱深度(m)" prop="sandDepth">
				<u-input :border="border" placeholder="请输入填砂管柱深度" v-model="model.sandDepth" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;"  :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="送砂水量" prop="waterVolume">
					<span v-if="model.waterVolume"> {{model.waterVolume}} m³ </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">送砂水量=油管内容积Q-混砂水量Q2</view>
				<view class="u-item-desc"> =填砂管柱深度×每米油管内容积-V砂×2</view>
				<view class="u-item-desc">注：填砂完毕后，送砂水量Q1加上混砂水量Q2不大于油管内容积Q。</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					tubingVolume: '',
					sandVolume: '',
					sandDepth: '',
					waterVolume: ''
				},
				rules: {
					tubingVolume: [{
						required: true,
						message: '请输入油管内容积',
						trigger: 'blur'
					}],
					sandVolume: [{
						required: true,
						message: '请输入填砂量',
						trigger: 'blur'
					}],
					sandDepth: [{
						required: true,
						message: '请输入填砂管柱深度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const Q = parseFloat(this.model.tubingVolume);
						const V = parseFloat(this.model.sandVolume);
						const depth = parseFloat(this.model.sandDepth);
						
						
						// 计算送砂水量 = 油管内容积 - 混砂水量
						this.model.waterVolume = (Q*depth-V*2).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>